import router from '@/router';
import { AppAxiosResponse } from '@/types/http';
import jsCookie from 'js-cookie';

const obj = {
  507: () => {},
  401: () => {
    jsCookie.remove('Authorization');
    router.push({ path: '/login' });
  },
  default: (msg: string) => {
    window.$message.error(msg);
  }
};

export default function (response: AppAxiosResponse) {
  if(Object.prototype.hasOwnProperty.call(obj, response.data.code)) {
    obj[response.data?.code](response.data.message);
    return;
  }
  obj.default(response.data.message || '请求失败！');
}
